/*
 * Copyright (c) 2003-2004, Inversoft, All Rights Reserved
 */
package org.emergent.antbite.savant;


import java.io.IOException;


/**
 * <p>
 * This class is the default local project builder. This uses
 * the java.lang.Runtime class to exec ant with the information
 * from the local project.
 * </p>
 *
 * @author Brian Pontarelli
 */
public class DefaultLocalProjectBuilder implements LocalProjectBuilder {

    /**
     * Builds the given LocalProject.
     */
    public void build(LocalProject project) throws SavantException {
        String[] cmd = new String[] {"ant", "-f", project.getAntfile(),
            project.getTarget()};
        try {
            java.lang.Process process = Runtime.getRuntime().exec(cmd, null,
                project.getDir());
            if (process.exitValue() != 0) {
                throw new SavantException("Build of project [" + project.getName() +
                    "] failed");
            }
        } catch (IOException ioe) {
            throw new SavantException("Unable to build local project [" +
                project.getName() + "] due to [" + ioe.getMessage() + "]");
        }
    }
}
